<?php

//说明文档
//http://langlanglang.gitee.io/poster-doc/
//composer require kkokk/poster

public function poster(){
    $row = $this->model->get($this->request->get('id'));
    if(empty($row)){
        $this->error('信息异常');
    }
    if(!$row['image']){
        $this->error('请先上传封面图');
    }

    try {
        $addImage = "https://guo-nei.oss-cn-beijing.aliyuncs.com/beijing/Xixi/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20211108014151.jpg";

        $area = Db::name('area')->where('id',$row['area_id'])->find();

        $tt = time();
        $path= root_path().'/public/uploads/poster/model_'.$tt.'.png';
        @unlink(root_path().'public'.$row['poster']);
//    dump(root_path().'assets/img/poster.png');
//    dump(is_file(root_path().'/public/assets/img/poster.png'));die;
        $result = PosterManager::Poster($path) //生成海报，这里写保存路径和文件名，可以指定图片后缀。默认png
        ->buildImDst(root_path().'public/assets/img/poster.png')
            ->buildText(date('Y/m/d',$row['updatetime']),102,48,36,[174, 174, 178,1],0,root_path()."public/assets/fonts/PingFang SC Bold.ttf")
            ->buildText($area['shortname'].'/'.ucfirst($area['pinyin']),344,48,36,[174, 174, 178,1],0,root_path()."public/assets/fonts/PingFang SC Bold.ttf")
            ->buildText($row['age'].'岁',540,200,36,[174, 174, 178,1],0,root_path()."public/assets/fonts/PingFang SC Bold.ttf")
            ->buildText($row['height'].'cm',520,390,36,[174, 174, 178,1],0,root_path()."public/assets/fonts/PingFang SC Bold.ttf")
            ->buildText($row['weight'].'kg',538,580,36,[174, 174, 178,1],0,root_path()."public/assets/fonts/PingFang SC Bold.ttf")
//        ->buildText($row['enname']?"{$row['name']} / {$row['enname']}":$row['name'],36,870,32,[174, 174, 178,1],0,root_path()."public/assets/fonts/PingFang SC Bold.ttf")
            ->buildText("{$row['name']} / {$row['enname']}",36,870,32,[174, 174, 178,1],0,root_path()."public/assets/fonts/PingFang SC Bold.ttf")
            ->buildImage($row['image'],0,138,0,0,440,614)
            ->buildQr($this->request->domain().'/index/index/detail.html?id='.$row['id'],394,796,0,0,0,0,4,1)
            ->getPoster();

        $this->model->where('id',$row['id'])->update(['poster'=>'/uploads/poster/model_'.$tt.'.png']);
        $this->success();
    } catch (Exception $e){

//            dump($e->getMessage());
        $this->error( $e->getMessage());
    }
}

}

